﻿@{
    var gridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSize;
    
    //page title
    ViewBag.Title = T("Admin.Catalog.ProductTags").Text;
}
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "product-tags-form" }))
{
    <div class="section-header">
        <div class="title">
            <img src="@Url.Content("~/Administration/Content/images/ico-catalog.png")" alt="" />
            @T("Admin.Catalog.ProductTags")
        </div>
    </div>
    <table class="adminContent">
        <tr>
            <td>
                <div id="product-tags-grid"></div>

                <script>
                    $(document).ready(function () {
                        $("#product-tags-grid").kendoGrid({
                            dataSource: {
                                type: "json",
                                transport: {
                                    read: {
                                        url: "@Html.Raw(Url.Action("ProductTags", "Product"))",
                                        type: "POST",
                                        dataType: "json"
                                    },
                                    destroy: {
                                        url: "@Html.Raw(Url.Action("ProductTagDelete", "Product"))",
                                        type: "POST",
                                        dataType: "json"
                                    }
                                },
                                schema: {
                                    data: "Data",
                                    total: "Total",
                                    errors: "Errors",
                                    model: {
                                        id: "Id",
                                        fields: {
                                            Name: { editable: true, type: "string" },
                                            Value: { editable: true, type: "string" },
                                            Store: { editable: true, type: "string" },
                                            StoreId: { editable: true, type: "number" },
                                            Id: { editable: false, type: "number" }
                                        }
                                    }
                                },
                                requestEnd: function (e) {
                                    if (e.type == "create" || e.type == "update") {
                                        this.read();
                                    }
                                },
                                error: function (e) {
                                    display_kendoui_grid_error(e);
                                    // Cancel the changes
                                    this.cancelChanges();
                                },
                                pageSize: @(gridPageSize),
                                serverPaging: true,
                                serverFiltering: true,
                                serverSorting: true
                            },
                            pageable: {
                                refresh: true
                            },
                            editable: {
                                confirmation: false,
                                mode: "inline"
                            },
                            scrollable: false,
                            columns: [{
                                field: "Name",
                                title: "@T("Admin.Catalog.ProductTags.Fields.Name")",
                                width: 300
                            }, {
                                field: "ProductCount",
                                title: "@T("Admin.Catalog.ProductTags.Fields.ProductCount")",
                                width: 150
                            }, {
                                field: "Id",
                                title: "@T("Admin.Common.Edit")",
                                width: 150,
                                template: "<input type='submit' value='@T("Admin.Common.Edit")' onclick=\"javascript:OpenWindow('@Url.Content("~/Admin/Product/EditProductTag/")#=Id#?btnId=btnRefresh&formId=product-tags-form', 800, 250, true); return false;\" class='k-button' />"
                            }, {
                                command: { name: "destroy", text: "@T("Admin.Common.Delete")" },
                                title: "@T("Admin.Common.Delete")",
                                width: 100
                            }]
                        });
                    });
                </script>       
            </td>
        </tr>
        <tr>
            <td width="100%">
                <input type="submit" id="btnRefresh" name="btnRefresh" style="display: none" />
                <script type="text/javascript">
                    $(document).ready(function () {
                        $('#btnRefresh').click(function () {
                            //refresh grid
                            var grid = $("#product-tags-grid").data('kendoGrid');
                            grid.dataSource.read();

                            //return false to don't reload a page
                            return false;
                        });
                    });
                </script>
            </td>
        </tr>
    </table>
}